﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;

namespace App
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CallSteven();
            //Process p = new Process();
            //p.StartInfo.FileName = Server.MapPath("./").Trim('\\').Substring(0, Server.MapPath("./").Trim('\\').LastIndexOf('\\')) + "\\GetNewsForm\\bin\\Release\\GetNewsForm.exe"; //换成你要执行的
            //p.StartInfo.UseShellExecute = false;
            //p.StartInfo.RedirectStandardInput = true;
            //p.StartInfo.RedirectStandardOutput = true;
            //p.StartInfo.RedirectStandardError = true;
            //p.StartInfo.CreateNoWindow = true;
            //string strOutput = null;
            //try
            //{
            //    p.Start();
            //    //p.StandardInput.WriteLine(commandText);
            //    //p.StandardInput.WriteLine("exit");
            //    strOutput = p.StandardOutput.ReadToEnd();
            //    //p.WaitForExit();
            //    //p.Close();
            //}
            //catch (Exception ex)
            //{
            //    strOutput = ex.Message;
            //}
            ////return strOutput;
            //Response.Write(strOutput);
        }

        public void CallSteven()
        {
            string strCmd = "";
            DateTime dt = DateTime.Now;

            //注意：需要引入System.Diagnostics;
            Process prc = new Process();

            try
            {
                //指定调用的可执行文件
                strCmd += "D:\\WorkSpace\\EMPower\\EMPower\\GetNewsForm\\bin\\Release\\GetNewsForm.exe ";

                //如果可执行文件需要接收参数就加下下面这句，不同参数之间用空格隔开
                //strCmd += 参数1 + " " + 参数2 + " " + 参数n;

                //调用cmd.exe在命令提示符下执行可执行文件
                prc.StartInfo.FileName = "cmd.exe";
                prc.StartInfo.Arguments = " /c " + strCmd;
                prc.StartInfo.UseShellExecute = false;
                prc.StartInfo.RedirectStandardError = true;
                prc.StartInfo.RedirectStandardOutput = true;
                prc.StartInfo.RedirectStandardInput = true;
                prc.StartInfo.CreateNoWindow = false;

                prc.Start();

            }
            catch (Exception exU)
            {
                if (!prc.HasExited)
                {
                    prc.Close();
                }

                throw new Exception(exU.Message.ToString());
            }
        }
    }
}
